import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath } from 'node:url'
import packageJson from './package.json'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, './')

  return {
    root: './',
    base: './',
    define: {
      __PACKAGE_JSON_NAME__: JSON.stringify(packageJson.name),
    },
    plugins: [vue()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src/', import.meta.url)),
      },
    },
    server: {
      proxy: {
        '/proxy': {
          target: env.VITE_BASE_URL,
          changeOrigin: true,
          rewrite: (path: string) => path.replace(/^\/proxy/, ''),
        },
      },
    },
    build: {
      target: 'chrome87',
      cssTarget: 'chrome61',
    },
  }
})
